<%@ page import="java.sql.Statement" import="java.sql.ResultSet" import="java.sql.Connection" %>
<%@page import="connection.DBConnection"%>
<%@page import="java.util.*" %>
<%@page import="java.text.SimpleDateFormat" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Sales Voucher Report</title>
</head>
<body>

<h2 align="center"> Sales Voucher Report</h2>
<form name="fr11" method="post">

  <%
        String exportToExcel = request.getParameter("exportToExcel");
        if (exportToExcel != null && exportToExcel.toString().equalsIgnoreCase("YES")) 
        {
            response.setContentType("application/vnd.ms-excel");
            response.setHeader("Content-Disposition", "inline; filename=" + "SalesVoucherReport.xls");
 
        }
    %>

<table border=1 align="center"> 
<tr>
	<th>Invoice Number</th>
	<th>Date</th>
	<th>Customer Name</th>
	<th>Customer Code</th>
	<th>Product Name</th>
	<th>Product Quantity</th>
	<th>Product Rate</th>
	<th>Net Amount</th>
	<th>Taxation Category</th>
	<th>Tax Amount</th>
	<th>Transport Charges</th>
	<th>Total Amount</th>
	<th>Credit Limit</th>
</tr>

		<%  DBConnection dbc=new DBConnection();
			Connection con=dbc.getNewConnection();
			Statement st = null;
			ResultSet rs = null;
			
			double snet=0.0,stax=0.0,stransport=0.0,stotal=0.0;
			double sv8=0.0,sv10=0.0,sv11=0.0,sv12=0.0;
			try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select * from SalesVoucher2 where status=1"); %>
	        	
       		 <%  while(rs.next()){ %>
<tr>
            		<td><%= rs.getString(1)%></td>
            		
            		<% String svdate= rs.getString(2); 
           	    		 SimpleDateFormat fromsql = new SimpleDateFormat("yyyy-MM-dd");
        				 SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
        		 		 String newdate =formatter.format(fromsql.parse(svdate));
            		%>
            		<td><%=newdate %></td>
            		<td><%= rs.getString(3)%></td>
            		<td><%= rs.getString(4)%></td>
            		<td><%= rs.getString(5)%></td>
 					<td><%= rs.getDouble(6)%></td>
 					<td><%= rs.getDouble(7)%></td>
 					<% sv8=rs.getDouble(8); %>           		
            		<td><%=sv8%></td>  <%--net amount --%>
            		
            		<td><%= rs.getDouble(9)%></td>
            		
            		<% sv10=rs.getDouble(10); %>
            		<td><%=sv10%></td> <%--tax amount --%>
            		
            		<% sv11=rs.getDouble(11); %>
            		<td><%=sv11%></td> <%--transport amount --%>
            		
            		<% sv12= rs.getDouble(12); %>
            		<td><%=sv12 %></td> <%--total amount --%>
            		<td><%= rs.getInt(13)%></td>
            		            		
</tr>
        		<%  snet=snet+sv8;
	    			stax=stax+sv10;
    				stransport=stransport+sv11;
    				stotal=stotal+sv12;
        			} 
        			
        		%>
        		
  
	 		<% }
			catch(Exception e){} %>
			
<tr>
	<td> <b> Total </b></td>
	<td> </td>
	<td> </td>
	<td> </td>
	<td> </td>
	<td> </td>
	<td> </td>
	<td> <%=snet %></td>
	<td> </td>
	<td> <%=stax %></td>
	<td> <%=stransport %></td>
	<td> <%=stotal %></td>
	<td> </td>
	
</tr>	
			
<%--<tr>
		<td> ${CMR.rbname} </td> 
		<td> ${CMR.renum} </td>
		<td> ${CMR.date} </td>
		<td> ${CMR.rcheque} </td>
		<td> ${CMR.raccname} </td>
		<td> ${CMR.ramount} </td>
		<td> ${CMR.raccname2} </td>
		<td> ${CMR.ramount2} </td>
		<td> ${CMR.rnar} </td>

</tr>
--%>
</table>
<br><br> 
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    <%
        if (exportToExcel == null) {
    %>
    <a href="SalesVoucherReport.jsp?exportToExcel=YES">Export to Excel</a>
    <%
        }
    %>
</form>

<br><br> 
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<form name="delete_form" action="SalesVoucherDeleteServlet">
<input type="text" name="delete"> 
<input type="submit" value="Delete Voucher">
<br><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="http://localhost:8081/BOA_Web/DeletedSalesVouchers.jsp">Deleted Sales Vouchers</a>

<center><input type="button" value="Print this page" onClick="window.print()"></center>
</form>



</body>
</html>